package com.eqdd.yiqidian.utils;

import com.arlib.floatingsearchview.FloatingSearchView;
import com.eqdd.yiqidian.R;
import com.jakewharton.rxbinding.widget.RxTextView;

import java.util.concurrent.TimeUnit;

import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by lv on 17-8-24.
 */

public class SearchUtil {
    public static void query(FloatingSearchView searchView,OnQuery onQuery){
        RxTextView.textChangeEvents(searchView.findViewById(R.id.search_bar_text))
                .debounce(600, TimeUnit.MILLISECONDS)  //debounce:每次文本更改后有300毫秒的缓冲时间，默认在computation调度器
                .observeOn(AndroidSchedulers.mainThread())  //触发后回到Android主线程调度器
                .subscribe(textViewTextChangeEvent -> onQuery.query(textViewTextChangeEvent.text()));
    }
    public interface OnQuery{
        void query(CharSequence query);
    }
}
